
<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2017/7/20
  Time: 16:17
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>
<c:set var="resroot" value="${ctx}/common"/>
<c:set var="jsroot" value="${resroot}/js"/>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>注册</title>
  <style type="text/css">
    a{
      text-decoration: none;
      color: #ff4001;
    }
    h1{
      font-weight: normal;
    }
    .header{
      padding: 29px 0;
      border-bottom: 1px solid #e5e5e5;
      height: 20px;
      right: 0;
      left:0;

    }
    .nav h1{
      font-size: 18px;
      line-height: 0px;
      padding-left: 30px;
    }
    .nav p{
      line-height: 0;
    }


    input{
      display: block;
      margin: 0 auto;
      margin-top: 30px;
    }

    #userName{
      background:url("${ctx}/common/images/login/user.png") no-repeat 0px;
      padding-left: 25px;
      width: 200px;
      height: 25px;
    }
    #phoneNum{
      background:url("${ctx}/common/images/login/phone.png") no-repeat -2px -3px;
      padding-left: 25px;
      width: 200px;
      height: 25px;
    }
    #password{
      background:url("${ctx}/common/images/login/pwd.png") no-repeat 0px 0px;
      padding-left: 25px;
      width: 200px;
      height: 25px;
    }
    #con_password{
      padding-left: 25px;
      width: 200px;
      height: 25px;
      border-bottom: 1px;
    }
    #num{
      background:url("${ctx}/common/images/login/key.png") no-repeat -2px -3px;
      width: 200px;
      height: 25px;
      padding-left: 25px;
    }
    .btn {
      display: block;
      width: 100px;
      height: 35px;
      line-height: 20px;
      background: #ff4001;
      color: #ffffff;
      font-size: 16px;
      margin: auto;
    }
    .btn_1{
      display: block;
      width: 200px;
      height: 35px;
      line-height: 20px;
      background: #ff4001;
      color: #ffffff;
      font-size: 16px;
      margin: auto;
      margin-top: 30px;
    }
  </style>
</head>
<body>
<div class="header">
  <div class="nav">
    <div style="float: left ;padding-left: 70px">
      <a href="${ctx}/home.action">
        <img src="${ctx}/common/images/home/logo.png" alt="logo">
      </a>

      <h1 style="float: left">用户注册</h1>
      <p style="float: right; margin-right: 60px">
        <small>已有诺心账号？<a href="${ctx}/login.action" >请登录</a></small>
      </p>
    </div>
  </div>
</div>
<div >

  <div class="container text-center">
    <div class="form" style="margin-top: 45px">
      <span><input type="text" id="userName" placeholder="请输入用户名"></span>
      <span><input type="text" id="phoneNum" placeholder="手机号码"></span>
      <span><input type="password" id="password" placeholder="6-20位密码"></span>
      <span><input type="password" id="con_password" placeholder="确认密码"></span>
      <input type="text" id="num" placeholder="手机验证码">
      <button class="btn">发送验证码</button>
    </div>

    <button class="btn_1" onclick="signup()">立即注册 </button>
  </div>
</div>

  <script src="${ctx}/common/js/jQuery-2.1.4.min.js"></script>
  <script>
    function signup(){
      var userName = $("#userName").val().trim();
      var password = $("#password").val().trim();
      var password1= $("#con_password").val().trim();
      var phoneNum= $("#phoneNum").val().trim();
      if(!userName || !password || !phoneNum){
        alert("用户名、密码或手机号码不能为空");
        return;
      }
      if(password.length > 5 && 21 < password.length){
        alert("密码在6~20位");
        return;
      }
      if(password != password1){
        alert("两次输入的密码不一致");
        return;
      }
      $.ajax({
        url:"${ctx}/signup.action",
        type: "POST",
        datatype:"json",
        data:{
          userName: userName,
          password: password,
          phoneNum: phoneNum
        },
        success:function(result){
            if(result.success) {
              location.href = '${ctx}/login.action';
            }else{
              alert(result.error);
            }
          }
        });
    }
  </script>
</body>
</html>
